package com.changgou.order.listener;

import com.alibaba.fastjson.JSON;
import com.changgou.order.config.RabbitMQConfig;
import com.changgou.order.pojo.Order;
import com.changgou.order.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zero
 * @date 2020/7/14
 */

@Component
public class OrderPayListener {

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = RabbitMQConfig.ORDER_PAY)
    public void receiveOrderPayMessage(String message){
        System.out.println("接收到支付服务的消息:" + message);

        Map<String,String> map = JSON.parseObject(message, Map.class);
        //取出数据
        String orderId = map.get("orderId");
        String transactionId = map.get("transactionId");

        //调用订单业务层,完成订单数据的修改
        orderService.updatePayStatus(orderId,transactionId);

    }



}
